Learning Flex Basics (Part 1): Creating Your First Flex Application
Table of Contents
- Introduction
- A Brief Overview of Macromedia Flex
- Building the Application
- Create the Application Object
- Add a Panel for the Application Layout
- Add a Label for the View Header
- Add an Array of Objects to Define the Coffee Blends
- Add a ComboBox to Display the Coffee Blends
- Add a Text Control to Display the Description
- Add a Button to Add a Coffee Blend to the Shopping Cart
- Add a List Control for the Shopping Cart
- Add a Script to Handle the Button Click Event
- Complete Code Listing for firstapp.mxml
- Where to Go From Here
Add a ComboBox to Display the Coffee Blends
The Flex ComboBox is similar to an HTML select control, though more robust. The dataProvider property sets the items to display in an array of simple values or objects. You can create the array directly within a dataProvider block, but a more common approach is to create or import the data elsewhere and bind it to the dataProvider property:
<mx:ComboBox id="myCombo" dataProvider="{myArray}"/>
The curly braces signal the compiler that what's inside is an expression or variable to evaluate rather than a literal string.
If the objects contain label and data properties,
these are used automatically for the displayed items and data associated with
them—the data can be a scalar value or complex type such as an object.
If the objects do not have label and data properties, then the entire objects
are used for the item data properties, and the label value is set to one of
the object properties using the labelField property of the ComboBox.
-
Add a ComboBox control after the Label, giving an
idofcoffeeComboand using thedataProviderproperty to bind the ComboBox to the coffeeArray you created in the previous step:<mx:ComboBox id="coffeeCombo" dataProvider="{coffeeArray}"/>